package com.itstherules.jmsunit.util;

import java.util.Enumeration;

import javax.jms.JMSException;
import javax.jms.Message;

public final class HeadersCopier {
	@SuppressWarnings("unchecked")
	public final Message copyMessageHeaders(Message from, Message to) throws JMSException {
		
		Enumeration<String> headerNames = to.getPropertyNames();
		while (headerNames.hasMoreElements()) {
			String name = (String) headerNames.nextElement();
			if (!name.startsWith("JMSX")) {
				from.setStringProperty(name, to.getStringProperty(name));
			}
		}
		from.setJMSCorrelationID(to.getJMSCorrelationID());
		from.setJMSDestination(to.getJMSDestination());
		from.setJMSMessageID(to.getJMSMessageID());
		from.setJMSReplyTo(to.getJMSReplyTo());
		from.setJMSType(to.getJMSType());
		return from;
	}
}
